Imports System



Structure MyStruct


    Private x As Integer
    Private Shared path As String
    Private Shared graph(15, 15) As Integer
    Private Shared setv(15), predecessor(15), mark(15), pathestimate(15) As Integer

    Private Shared v1() As Integer= {1, 1, 1, 2, 3}
    Private Shared v2() As Integer= {2, 3, 4, 4, 4}
    Private Shared edge() As Integer= {3, 3, 6, 2, 1}

    Private Shared source, num_of_vertices, num_of_edges As Integer


    
    Public Sub read(ByVal nv As Integer, ByVal ne As Integer)

        num_of_vertices = nv
        num_of_edges = ne
        source = 1

        For i As Integer = 1 To 4
            Dim check As Integer
            check = 0
            For j As Integer = 1 To 4
                If i = j Then
                    graph(i, j) = 0

                Else
                    For e As Integer = 1 To v1.Rank


                        If (v1(e) = i And v2(e) = j) Or (v1(e) = j And v2(e) = i) Then
                            graph(i, j) = edge(e)
                            check = 1
                        End If
                        If check = 0 Then
                            graph(i, j) = -1
                        End If
                    Next
                End If


            Next
        Next

 


    End Sub


    Public Sub initialize()

        Dim i As Integer
        For i = 1 To i <= num_of_vertices
            mark(i) = 0
            pathestimate(i) = 100
            predecessor(i) = 0
        Next
        pathestimate(source) = 0
    End Sub

    Public Sub algorithm()
        initialize()
        Dim count, i, u As Integer
        count = 0

        While count < num_of_vertices
            u = minimum()
            setv(++count) = u
            'count += 1
            mark(u) = 1
            For i = 1 To num_of_vertices
                If graph(u, i) > 0 Then
                    If mark(i) <> 1 Then
                        If pathestimate(i) > pathestimate(u) + graph(u, i) Then
                            pathestimate(i) = pathestimate(u) + graph(u, i)
                            predecessor(i) = u
                        End If
                    End If
                End If

            Next
        End While

    End Sub

    Public Function printpath(ByVal i As Integer) As String
        'cout<<endl;
        If i = source Then
            path = path & source
        ElseIf predecessor(i) = 0 Then
            'cout<<no path
        Else
            printpath(predecessor(i))
            path = path & i & "    /   "

        End If
        Return path
    End Function

    Public Function output() As String
        Dim i As Integer = 1
        While i <= num_of_vertices
            path = printpath(i)
            If pathestimate(i) <> -1 Then
                path = path & "  --> (" & pathestimate(i) & ")"
            End If
            'cout<<endl
            i += 1
        End While
        'cout<<endl
        Return path
    End Function
    Public Shared Function minimum() As Integer
        Dim min As Integer
        min = 999
        Dim i, t As Integer
        i = 1

        While i < num_of_vertices
            If mark(i) <> 1 Then
                If min > pathestimate(i) Then
                    min = pathestimate(i)
                    t = i
                End If
            End If
            i = i + 1
        End While
        Return t


    End Function



End Structure





Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ms As New MyStruct
        'ms.read(CType(TextBox1.Text, Integer), CType(TextBox2.Text, Integer))
        ms.read(4, 5)

        RichTextBox1.Text = ms.output()



    End Sub
End Class